package com.central.user.controller;

import com.central.common.model.LoginAppUser;
import com.central.user.service.ISysUserAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: ly
 * @date: 2020/11/17 5:15 下午
 * @email: 664162337@qq.com
 */
@Slf4j
@RestController
@Api(tags = "账户模块api")
@RefreshScope
public class SysUserAccountController {

    @Autowired
    private ISysUserAccountService accountService;

    /**
     *
     * @param username
     * @return
     */
    @ApiOperation(value = "通过username获取账号")
    @GetMapping(value = "/accounts/username/{username}")
    LoginAppUser findByUsername(@PathVariable("username") String username) {
        return accountService.findByUsername(username);
    }

    /**
     *
     * @param userId
     * @return
     */
    @ApiOperation(value = "通过用户id获取账号")
    @GetMapping("/accounts/{userId}")
    LoginAppUser findByUserId(@PathVariable("userId") String userId) {
        return accountService.findByUserId(userId);
    }

    /**
     * 是否是系统的超级管理员
     * @param username
     * @return
     */
    @GetMapping(value = "/accounts/super/{username}")
    boolean isSupperAdminUser(@PathVariable("username") String username) {
        return accountService.isSupperAdminUser(username);
    }
}
